const userService = require('../services/userService')

const userController = {
    userFind: async(req,res,next)=>{
        if(req.query.id){
            let data = await userService.userfindone(req.query.id)
            res.send(data)
        }else if(req.query.username && req.query.password){
            let data = await userService.userfindwho(req.query.username,req.query.password) 
            if(data){
                res.send(data)
            }else{
                res.status(404).send({allow:false,message:'账号或密码错误'})
            }
        }else{
            let data = await userService.userfindmany()
            res.send(data)
        }
    },

    userAdd: async(req,res,next)=>{
        let data = await userService.useradd(req.body)
        if(data){
            res.send({ok:1})
        }else{
            res.send({no:1})
        }
    },

    userUpdata: async(req,res,next)=>{
        let data = await userService.userupdata(req.body)
        console.log(data,1)
        if(data){
            res.send(data[0])
        }else{
            res.send({no:1})
        }
    }
}

module.exports = userController